package com.chocho.producerserver.dao;

import com.chocho.producerserver.bean.User;
import com.chocho.producerserver.bean.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by chocho on 2022/3/29.
 */
@Mapper
@Repository
public interface UserroleDao {
    //根据用户名查询用户角色信息
    @Select("SELECT role_id from op_user_role " +
            "LEFT JOIN op_user ON op_user_role.user_id = op_user.user_id " +
            "WHERE op_user.user_name = #{username}")
    List<String> selectByUsername(String username);

    @Delete("DELETE FROM op_user_role WHERE role_id = #{id}")
    Integer deleteByRoleID(String id);

    @Delete("DELETE FROM op_user_role WHERE userrole_id = #{userid}")
    void deleteByUserID(String userid);

    @Insert("INSERT INTO op_user_role (userrole_id, user_id, role_id) " +
            "VALUES(#{userroleId}, #{userId}, #{roleId})")
    public int insert(UserRole user);
}
